package com.example.linkedlist;

import com.example.entity.DoubleLinkedList;
import com.example.entity.DoubleLinkedNode;

/**
 * @Author: wanqian
 * @Date: 2021/1/26 11:59
 */
public class DoubleLinkedListDemo {
    public static void main(String[] args) {

        DoubleLinkedNode jack = new DoubleLinkedNode(1, "Jack");
        DoubleLinkedNode tom = new DoubleLinkedNode(2, "Tom");
        DoubleLinkedNode kris = new DoubleLinkedNode(3, "Kris");
        DoubleLinkedNode matthew = new DoubleLinkedNode(4, "Matthew");

        DoubleLinkedList linkedList = new DoubleLinkedList();
        linkedList.addNode(kris);
        linkedList.addNode(matthew);
        linkedList.addNode(jack);
        linkedList.addNode(tom);
        System.out.println("list为: ");
        linkedList.list();

        //遍历
//        linkedList.list();
//        linkedList.reversePrint();

        //有效节点长度
        linkedList.length();

        //倒数第n个节点
//        linkedList.getFromEnd(2);
//        linkedList.getFromEnd(3);

        //反转链表
//        linkedList.reverse();
//        linkedList.reverse2();
//        System.out.println("反转链表");
//        linkedList.list();

        //删除
//        System.out.println("删除1号");
//        linkedList.delete(1);
//        linkedList.list();

        //修改节点
//        System.out.println("修改2号");
//        DoubleLinkedNode Sheldon = new DoubleLinkedNode(2, "Sheldon");
//        linkedList.update(Sheldon);
//        linkedList.list();
    }

}
